//
//  VolumeBrightnessView.swift
//  GenericProjectForSwift
//
//  Created by 皮蛋菌 on 2023/5/22.
//  Copyright © 2023 漠然丶情到深处. All rights reserved.
//

import UIKit

class VolumeBrightnessView: UIView {
    
    var valueLabel: UILabel!
    var progressView: UIProgressView!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
//        self.backgroundColor = UIColor.ls_color(withHexString: "000000", alpha: 0.4)
        createSubViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func createSubViews() {
        // 创建数值标签
        valueLabel = UILabel()
        valueLabel.textAlignment = .center
        valueLabel.textColor = .white
        valueLabel.font = UIFont.systemFont(ofSize: LSSYRealValue(value1: 12, value2: 24))
        addSubview(valueLabel)
        valueLabel.snp.makeConstraints({ make in
            make.top.equalTo(self).offset(0);
            make.left.equalTo(self).offset(0);
            make.size.equalTo(CGSizeMake(LSSYRealValue(value1: 40, value2: 80), LSSYRealValue(value1: 20, value2: 40)));
        })
        
        
        // 创建进度条
        progressView = UIProgressView()
        progressView.progressTintColor = .green
        progressView.trackTintColor = .lightGray
        progressView.transform = CGAffineTransform(scaleX: 1.0, y: 0.3)
        addSubview(progressView)
        progressView.snp.makeConstraints { make in
            make.centerY.equalTo(self.valueLabel.snp.centerY);
            make.left.equalTo(self.valueLabel.snp.right).offset(LSSYRealValue(value1: 5, value2: 10));
            make.right.equalTo(self.snp.right).offset(LSSYRealValue(value1: 10, value2: 20));
            make.height.equalTo(LSSYRealValue(value1: 10, value2: 20));
        }
    }
    
    func setProgress(_ progress: Float) {
        progressView.progress = progress
        let valueString = String(format: "%.0f%%", progress * 100)
        valueLabel.text = valueString
    }

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
